package com.st.emps.project.service;

import java.util.List;

import com.st.emps.project.dao.ProjectDao;
import com.st.emps.project.model.ProjectModel;
import com.st.emps.util.MD5;

public class ProjectService {
	
	private ProjectDao dao = new ProjectDao();
	
	public String insert(ProjectModel model) {
		if(dao.select(new ProjectModel(model.getCode()))== null||dao.select(new ProjectModel(model.getCode())).isEmpty()) {
			return dao.insert(model)+"";
		}else
		return "repeat";

	}
	public String delete(ProjectModel model) {
		return dao.delete(model)+"";

	}
	public String update(ProjectModel model) {
		return dao.update(model)+"";

	}
	public List<ProjectModel> selectList(ProjectModel model) {
		String code = model.getCode();
		if(code==null)
			code ="";
		model.setCode("%"+code+"%");
		String name = model.getName();
		if(name==null)
			name ="";
		model.setName("%"+name+"%");
		return dao.select(model);

	}
	public ProjectModel selectModel(ProjectModel model) {
		ProjectModel tmp = new ProjectModel(model.getCode());
		List<ProjectModel> list = selectList(tmp);
		return list==null||list.isEmpty()?null:list.get(0);

	}

	public Object selectCount(ProjectModel model) {
		ProjectModel tmp = new ProjectModel();
		String code = model.getCode();
		if(code==null)
			code ="";
		tmp.setCode("%"+code+"%");
		String name = model.getName();
		if(name==null)
			name ="";
		tmp.setName("%"+name+"%");
		return dao.selectCount(tmp);
	}


	public String updateDepart(ProjectModel model) {
		return dao.updateDepart(model)+"";
	}
}
